<template>
    <el-row>
        <el-col :md="8" :offset="8">
            <el-form ref="form" :model="form">
                <el-form-item label="账号">
                    <el-input v-model="form.account"></el-input>
                </el-form-item>
                <el-form-item label="密码">
                    <el-input show-password v-model="form.login_pwd"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" :loading="onLogin" @click="login" native-type="submit">登录</el-button>
                </el-form-item>
            </el-form>

        </el-col>
        <el-form-item>
            <el-input type="textarea" v-model="tokenStore.token"></el-input>
        </el-form-item>
        <div>{{ tokenStore.token_exp }}</div>
    </el-row>
    
</template>

<script>

import {Token} from '@/store/token.js'

export default {
    
    

    data(){
        let form = {
            account : '',
            login_pwd : ''
        }
        return {
            form,
            onLogin : false,
            redirect : '/',
            tokenStore : Token()
        }
    },

    mounted(e){
        let red = this.$route.query?.redirect;
        this.redirect = red ? red : '/index'
    },
    // created (){
    //     this.submitHandler = debounce(this.login,5000)
    // },
    methods : {

        asyToken(){
            this.tokenStore.getToken().then(res=>{
                console.log(1,res)
            }).catch(er=>{
                console.log(1, er)
            })
            
        },

        login(){
            if(this.onLogin){
                return;
            }
            this.onLogin = true;
            this.tokenStore.userpwdLogin(this.form)
            .then(res=>{
                this.onLogin = false;
                this.$router.push(this.redirect)
            })
            .catch(err=>{
                this.onLogin = false;
            })
        }
    }
}
</script>